
#include "./empty.hpp"
/*参数定义：路过的人，土地属性，土地主人属性*/
bool Empty::PassFunction(User& user,std::vector<Land>& map,std::unordered_map<int,User*>& users){
	if (this->ownId==0) {
		if (user.GetStopNum()) {
			return false;
		}
		PrintStd("你来到了一块空地,是否购买(y/n)?");
		while (1) {
			auto get=GetStdInput();
			if (get!="y"&&get!="n") {
				PrintStd("输入错误");
				continue;
			}else if (get=="y") {
				if (user.GetMoney()<this->price) {
					PrintStd("你太穷了");
					break;
				}

				auto money=user.GetMoney();
				user.SetMoney(money-this->price);

				this->ownId=user.GetId();
				this->status=Sold;
				this->color=user.MapColor();
				this->input+=this->price;

				auto& house=*user.GetHouseMsg();
				house[pos]++;
				printf("你现在剩余的金钱为%d元\n",user.GetMoney());
			}
			break;
		}
	}else if(this->ownId==user.GetId()){
		if (user.GetStopNum()) {
			return false;
		}
		printf("你来到了自己的土地，你现在的房屋等级是：");
		switch (this->status)
		{
		case Sold:
			printf("空地\n");
			break;
		case Thatch:
			printf("茅屋\n");
			break;
		case Room:
			printf("洋房\n");
			break;
		case Edifice:
			printf("摩天楼\n");
			break;
		default:
			break;
		}
		if(this->status!=Edifice)
		{	
			PrintStd("请选择是否升级(y/n)?");
			while (1) {
				auto get=GetStdInput();
				if (get!="y"&&get!="n") {
					PrintStd("输入错误");
					continue;
				}else if (get=="y") {
					if (user.GetMoney()<this->price) {
						PrintStd("你太穷了");
						break;
					}

					auto money=user.GetMoney();
					user.SetMoney(money-this->price);//修改玩家金钱

					this->status=EmptyStatus((int)(this->status+1));//升级房屋
					this->color=user.MapColor();
					this->input+=this->price;//投入金额增加
					printf("你现在剩余的金钱为%d元\n",user.GetMoney());

				}
				break;
			}
		}else{
			PrintStd("你的房屋已经是最高等级，无需升级！");
		}
	}else {
		auto owner=this->ownId;
		auto money=user.GetMoney();
		auto ownermony=users[owner]->GetMoney();
		printf("你路过了");
		switch (owner)
		{
		case 1:
			printf("钱夫人");
			break;
		case 2:
			printf("阿土伯");
			break;
		case 3:
			printf("孙小美");
			break;
		case 4:
			printf("金贝贝");
			break;
		default:
			break;
		}
		printf("的土地，须缴纳%d元的租金\n",this->input/2);
		if((users[owner]->GetStatus())!=Hospital&&(users[owner]->GetStatus())!=Jail&&user.GetWealth()==0)	
		{
			if(money<(this->input/2))
			{	
				user.SetStatus(Bankruptcy);
				user.SetMoney(-1);
				PrintStd("你破产了！！！");
				return false;
				/* ownermony+=money; */
				/* users[owner]->SetMoney(ownermony); */
			}else{
				user.SetMoney(money-this->input/2);
				printf("你现在剩余的金钱为%d元\n",user.GetMoney());
				ownermony+=this->input/2;
				users[owner]->SetMoney(ownermony);
			}
		}else if ((users[owner]->GetStatus())==Hospital)
		{
			PrintStd("土地的主人在医院里，你可以免租金。");
		}else if ((users[owner]->GetStatus())==Jail)
		{
			PrintStd("土地的主人在监狱里，你可以免租金。");
		}else{
			PrintStd("财神附体，你可以免租金。");
		}	
	}
	return false;
}

char Empty::MapChar(){
	switch (this->status) {
	case Glade:
	case Sold:
		return '0';
	case Thatch:
		return '1';
	case Room:
		return '2';
	case Edifice:
		return '3';
	}
	return '0';
}

Color Empty::MapColor(){
	return this->color;
}
